package com.freemarker;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by
 * common controller
 * @author touni
 * @date 2019/4/8
 * @time 12:25
 */

@Controller
@RequestMapping("/student")
public class StudentController {

    @RequestMapping("/list")
    public String list(Map<String, Object> map) {  // refer TODO

        map.put("loginname", "touni");
        map.put("age", 25);
        List<Student> stuList = new ArrayList<>();
        stuList.add(new Student(1, "张三", "男"));
        stuList.add(new Student(3, "李四", "女"));
        stuList.add(new Student(89, "王五", "男"));
        map.put("stuList", stuList);
        return "index";

    }

     //该方法运行失败
    @RequestMapping("/list2")
    public String list2(Model model) {
        Map<String,Object> map = new HashMap<>();
        map.put("loginname", "德玛西亚");
        map.put("age", 26);
        List<Student> stuList = new ArrayList<>();
        stuList.add(new Student(25, "张三", "男"));
        stuList.add(new Student(26, "李四", "女"));
        stuList.add(new Student(29, "王五", "男"));
        map.put("stuList", stuList);

        model.addAttribute(map);  // todo 为何不可以直接在ftl中取出值  --mabey answer 多了一层map集合，需要取出值

        return "stumap";

    }

    @RequestMapping("/list3")
    public String list3(Model model) {
        model.addAttribute("loginname", "德玛西亚");
        model.addAttribute("age", 26);
        List<Student> stuList = new ArrayList<>();
        stuList.add(new Student(25, "张三", "男"));
        stuList.add(new Student(35, "李四", "女"));
        stuList.add(new Student(29, "王五", "男"));
        model.addAttribute("stuList", stuList);

        return "stumap";

    }












}
